package com.wanxi.util;

import sun.misc.BASE64Encoder;

import java.security.MessageDigest;

public class MD5 {
    public static String encoderByMd5(String str) {
        //确定计算方法
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            BASE64Encoder base64en = new BASE64Encoder();
            //加密后的字符串
            return base64en.encode(md5.digest(str.getBytes("utf-8")));
        } catch (Exception e) {
            e.printStackTrace();
        }
//        如果try报异常，则默认一个密码：aaaaaa
        return "C056Dl/oStNftflbnO6seQ==";
    }
}
